2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_COMPONENTCOLOURPROPERTY_JUCEHEADER__
27 #define __JUCER_COMPONENTCOLOURPROPERTY_JUCEHEADER__
29 #include "jucer_ColourPropertyComponent.h"
32 //==============================================================================
35 template <class ComponentType
>
36 class ComponentColourProperty
: public ColourPropertyComponent
,
37 private ChangeListener
40 ComponentColourProperty (const String
& name
,
41 ComponentType
* component_
,
42 JucerDocument
& document_
,
43 const bool canResetToDefault
)
44 : ColourPropertyComponent (name
, canResetToDefault
),
45 component (component_
),
48 document
.addChangeListener (this);
51 ~ComponentColourProperty()
53 document
.removeChangeListener (this);
56 void changeListenerCallback (ChangeBroadcaster
*)
62 ComponentType
* component
;
63 JucerDocument
& document
;
67 //==============================================================================
70 class ComponentColourIdProperty
: public ComponentColourProperty
<Component
>
73 //==============================================================================
74 ComponentColourIdProperty (Component
* const component_
,
75 JucerDocument
& document_
,
78 const bool canResetToDefault
)
79 : ComponentColourProperty
<Component
> (name
, component_
, document_
, canResetToDefault
),
84 ~ComponentColourIdProperty()
88 //==============================================================================
89 const Colour
getColour() const
91 return component
->findColour (colourId
);
94 void setColour (const Colour
& newColour
)
96 if (component
->findColour (colourId
) != newColour
)
98 document
.getUndoManager().undoCurrentTransactionOnly();
100 document
.perform (new ColourChangeAction (component
,
101 *document
.getComponentLayout(),
109 void resetToDefault()
111 document
.getUndoManager().undoCurrentTransactionOnly();
113 document
.perform (new ColourChangeAction (component
,
114 *document
.getComponentLayout(),
124 class ColourChangeAction
: public ComponentUndoableAction
<Component
>
127 ColourChangeAction (Component
* const comp
,
128 ComponentLayout
& layout
,
130 const Colour
& newColour_
,
131 const bool newColourIsDefault
)
132 : ComponentUndoableAction
<Component
> (comp
, layout
),
133 colourId (colourId_
),
134 newColour (newColour_
),
135 isDefault (newColourIsDefault
)
143 wasSpecified
= getComponent()->isColourSpecified (colourId
);
144 oldColour
= getComponent()->findColour (colourId
);
147 getComponent()->removeColour (colourId
);
149 getComponent()->setColour (colourId
, newColour
);
160 getComponent()->setColour (colourId
, oldColour
);
162 getComponent()->removeColour (colourId
);
164 TextEditor
* const te
= dynamic_cast <TextEditor
*> (getComponent());
166 te
->applyFontToAllText (te
->getFont());
173 Colour newColour
, oldColour
;
174 bool isDefault
, wasSpecified
;
179 #endif // __JUCER_COMPONENTCOLOURPROPERTY_JUCEHEADER__